<?php $this->load->view('header');?>
	<link rel="stylesheet" href="/css/realtest.css">
	
	<script language="Javascript" type="text/javascript">
	function trim (str) {
		var reg = /^\s+|\s+$/g;
		return str.replace(reg, "");
	}

    /** 判断字节长度 */
	function fucCheckLength(msg)
	{
	    var i,sum;
	    sum=0;
	    for(i=0;i <msg.length;i++){
	        if ((msg.charCodeAt(i)>=0) && (msg.charCodeAt(i) <=255)){
	            sum=sum+1;
	        }else{
	            sum=sum+2;
	        }
	    }
	    return sum;
	}

	/** debug使用，开启firebug，打印在控制台，
	 * 否则或者不支持firebug的浏览器，使用alert输出
	 * 使用：logit("a", b)*/
	function logit(key, value) {
		try {
			console.log(key, value );
		} catch(e) {
			alert(key + " : " + value);
		}
	}
	
	function isNullStr(str){
		if(trim(str) == 0){
			return true;
		}
		return false;
	}
	
	/** 检测（允许中文，英文，字母，数字，"_"，"."） */
  	function checkProName(str) {
  		var flag = true;
  		var testStr = /^[\u4e00-\u9fa5a-zA-Z0-9\.\_]*$/;
  		return testStr.test(str);
  	}
  	
  	/** 检测（允许英文，字母，数字，"_"，"."） */
  	function checkProVersion(str) {
  		var flag = true;
  		var testStr = /^[\a-zA-Z0-9\.\_]*$/;
  		return testStr.test(str);
  	}
  	
  	/** 检测（允许英文，字母，数字，"_"，"."） */
  	function checkProPackage(str) {
  		var flag = true;
  		var testStr = /^[\a-zA-Z\.]*$/;
  		return testStr.test(str);
  	}
    
  	function allErrorDialog() {
		var err = "服务器错误，请稍候再试";
		if ($("#all_error_dialog_div").is(":visible")) {
			return false;
		}
  		$("#all_error_dialog_div").html(err).fadeIn(200).delay(3000).fadeOut(600);
  	}
  	
  	/** 取消错误提示 */
	function cancelErrorDialog() {
		$("#all_error_dialog_div").dialog("destroy");
	}

	/**
	 * 左边树菜单和右边内容尺寸自适应，带滚动条
	 * @param opt [{"id": "side-bar", "h":100}....]
	 */
	function autoSize(opt){//alert(mainId);
		var height = document.documentElement.clientHeight;
		var h;
		$.each(opt, function(i, v){
			h = height - v["h"];
			$('#'+v["id"]).css('height',h+'px');
		});
//		$('#'+sideId).css('height',(height-220)+'px');
//		$('#'+mainId).css('height',(height-186)+'px');
	}
	
	function checkUserSession(data){
		if (data == null || data.length <= 0) {
			return 0;
		}
		if (data.indexOf("getUserSessionIsError") >= 0) {
			document.location.href = '/portal.action?op=Portal.login';
			return 1;
		}
		return 0;
	}

	/*datepicker local to zh-CN*/
	function localDatePicker() {
		$.datepicker.regional['zh-CN'] = { 
	        clearText: '清除', 
	        clearStatus: '清除已选日期', 
	        closeText: '关闭', 
	        closeStatus: '不改变当前选择', 
	        prevText: '<上月', 
	        prevStatus: '显示上月', 
	        prevBigText: '<<', 
	        prevBigStatus: '显示上一年', 
	        nextText: '下月>', 
	        nextStatus: '显示下月', 
	        nextBigText: '>>', 
	        nextBigStatus: '显示下一年', 
	        currentText: '今天', 
	        currentStatus: '显示本月', 
	        monthNames: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'], 
	        monthNamesShort: ['一','二','三','四','五','六', '七','八','九','十','十一','十二'], 
	        monthStatus: '选择月份', 
	        yearStatus: '选择年份', 
	        weekHeader: '周', 
	        weekStatus: '年内周次', 
	        dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'], 
	        dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'], 
	        dayNamesMin: ['日','一','二','三','四','五','六'], 
	        dayStatus: '设置 DD 为一周起始', 
	        dateStatus: '选择 m月 d日, DD', 
	        dateFormat: 'yy-mm-dd', 
	        firstDay: 1, 
	        initStatus: '请选择日期', 
	        isRTL: false
	    }; 
        
    	$.datepicker.setDefaults($.datepicker.regional['zh-CN']);
	}
    
    /** 缩放 */
    function resizePic(obj, rw,rh) {
    //    var cacheImg = new Image();
    //    cacheImg.src = obj.src;
        var lRealWidth = 0;
        var lRealHeight = 0;
        var ywidth = 180;
        var yheight = 240;
        lRealWidth = rw;
        lRealHeight = rh;
        var w = parseFloat(lRealWidth - ywidth);
        var h = parseFloat(lRealHeight - yheight);
        if (w > 0 || h > 0) {
            if (w >= h) {
                obj.width = lRealWidth * (ywidth/lRealWidth);
                obj.height = lRealHeight * (ywidth/lRealWidth);
            } else if (w < h) {
                obj.width = lRealWidth * (yheight/lRealHeight);
                obj.height = lRealHeight * (yheight/lRealHeight);
            }
        }
    }
	</script>
		
	<script type="text/javascript">
	//$(document).ready(function() {
	//	searchDevice();
	//});
	/*查询设备*/
	function searchDevice() {
		var actionurl = "/ajax/realtest.action?op=RealTest.deviceList&tz="
				+ Math.random();
		$.ajax({
			url : actionurl,
			type : "post",
			dataType : "html",
			data : $("#search_form").serialize(),
			async : true,
			cache : false,
			success : function(html) {
				$("#real_device_list").replaceWith(html);
			},
			error : function(msg) {
				//错误提示
				allErrorDialog();
			}
		});
	}
	
	/** 根据运营商的id获取对应的网络信息 */
	function getNetWorkInfo() {
		var operatorsId = $("#operators_id").val();
		$.ajax({
			url : "/ajax/mon.action?op=Newmon.getNetWork&tz="+ Math.random(),
			type : "post",
			dataType : "json",
			data : "operatorsId=" + operatorsId,
			async : true,
			cache : false,
			success : function(data) {
				createNetwork(data);
			},
			error : function(msg) {
			}
		});
	}
	
	/** 构建网络信息的select元素 */
	function createNetwork(data) {
		var newSelect = document.createElement("select");
		newSelect.id="network_type";
		newSelect.name="networkType";
		if (data == null) {
			newSelect.options[0] = new Option('全部网络', '');
		}else if (data.length == 0) {
			newSelect.options[0] = new Option('全部网络', '');
		} else {
			for (var i = 0; i < data.length; i++) {
				newSelect.options.add(new Option(data[i].networkName, data[i].id));
			}
		}
        $("#network_info").html(newSelect);
	}

	/*刷新城市信息*/
	function refreshCity() {
		var provinceCode = $("#provinceCode").val();
		$.ajax({
			type : "Post",
			url : "/ajax/realtest.action?op=RealTest.refreshCityList",
			dataType : "json",
			data : "provinceCode=" + provinceCode,
			cache : true,
			success : function(data) {
			var gSelect = "<select name='cityCode' id='cityCode'><option value=''>全部城市</option>";
				if (data != null) {
					for ( var j = 0; j < data.length; j++) {
						gSelect += "<option value=\"" + data[j].cityCode + "\">"
								+ data[j].cityName + "</option>";
					}
				}
				gSelect += "</select>";
				$("#cityCode").replaceWith(gSelect);
			},
			error : function(msg) {
				//错误提示
				allErrorDialog();
			}
		});
	}
	
	/*由平台id刷新品牌信息*/
	function refreshBrandList() {
		var syspfId = $("#syspfId").val();
		var syspfName = $("#syspfId").find("option:selected").text();
		//if(syspfId==""){
		//	return;//不查询
		//}
		$.ajax({
			type : "Post",
			url : "/ajax/realtest.action?op=RealTest.refreshBrandList",
			dataType : "json",
			data : "syspfName=" + syspfName + "&syspfId=" + syspfId,
			cache : true,
			success : function(data) {
				//加载品牌列表
				var gSelect = "<select id='brandId' name='brandId'> <option value='' selected>全部品牌</option>";
				if(null != data){
					for ( var j = 0; j < data.length; j++) {
						gSelect += "<option value=\"" + data[j].id + "\">"
						+ data[j].name + "</option>";
					}
				}
				gSelect += "</select>";
				$("#brandId").replaceWith(gSelect);
			},
			error : function(msg) {
				//错误提示
				allErrorDialog();
			}
		});
	}
	</script>
		
	<script type="text/javascript">
	
	/** 加载设备页面 */
	//查看监控详情
	function displayDevice(brandName, modelName, syspfName, syspfVer, dpiWidth, dpiHeight, networkName, area, imei, pcId, modelId, picUrlB) {
		$.ajax({
			url : "/realtest/bookDevice?"+ Math.random(),
			dataType : "html",
			data : "pcId="+pcId+"&imei="+imei+"&deviceId=1",
			async : false,
			cache : false,
			success : function(html) {
				//alert("html："+html);
				$("#real_test_content").replaceWith(html);
				$("#real_test_content").show();	
				$("#real_test_main").hide();
				$("#real_test_content_title").append(brandName+" "+modelName);
				$("#real_test_content_modelName").append(modelName);
				$("#real_test_content_brandName").append(brandName);
				$("#real_test_content_syspf").append(syspfName+" "+syspfVer);
				$("#real_test_content_network").append(networkName);
				$("#real_test_content_dpi").append(dpiWidth+"*"+dpiHeight);
				$("#real_test_content_area").append(area);
				$("#sel_imei").val(imei);
				$("#sel_modelId").val(modelId);
				$("#sel_pcId").val(pcId);
				$("#sel_picUrlB").val(picUrlB);
				//目前只支持android，这里写死
				if(syspfName!="Android") {
					$("#real_test_soft_span").hide();
				} else {
					$("#real_test_soft_span").show();
				}
				initEmulator();	
			},
			error : function(msg) {
				//错误提示
				//alert("msg："+msg);
				allErrorDialog();
			}
		});
	}
	function initEmulator() {
		var pcId = $("#sel_pcId").val();
		var imei = $("#sel_imei").val();
		var modelId = $("#sel_modelId").val();
		var picUrlB = $("#sel_picUrlB").val();	
		$.ajax({
			//url : "/ajax/realtest.action?op=RealTest.emulator&tz="+ Math.random(),
			url : "/realtest/emulator?"+ Math.random(),
			dataType : "html",
			data : "pcId="+pcId+"&imei="+imei+"&modelId="+modelId+"&picUrlB="+picUrlB,
			async : false,
			cache : false,
			success : function(html) {
				$("#flashContent").append(html);	
			},
			error : function(msg) {
				//错误提示
				//alert("msg："+msg);
				allErrorDialog();
			}
		});
	}
	</script>

	<!-- 服务器错误 信息提示 -->
	<div id="all_error_dialog_div" class="error_tips" style="display: none" title="提示"></div>
	<!-- 结束 服务器错误 信息提示 -->
		
	<div class="content"  id="real_test_main">
		<div class="page_url">
			<a href="<?php echo base_url();?>">首页</a>
			<span>&gt;</span>
			<strong>体验测试</strong>
		</div>
		<div class="mobile_list clearfix">
		
			<?php if(!empty($devices)):?>
			<?php foreach($devices as $device):?>
			<div class="mobile_box">
				<a href="javascript:;;" 
					onclick="javascript:displayDevice('<?php echo $device['brand_name'];?>','<?php echo $device['name'];?>','<?php echo $device['os_name'];?>','5.0.1','768','1024','','<?php echo $device['address'];?>','J30526W5Z39','2','193','http://file.testin.cn/getbasefile//phone/19/193/193-B.jpg')"
				>
					<?php if($device['isNew']):?>
					<em>NEW</em>
					<?php endif?>
					<h3>
						<span><?php echo $device['brand_name'] . ' ' . $device['name']?></span>
					</h3>
					<dl>
						<dt>
							<img src="<?php echo getImageUrl($device['image']);?>" width="70" height="120" alt="" />
						</dt>
						<dd class="button">
							马上使用
							<input type="hidden" name="imei" value="J30526W5Z39">
							<input type="hidden" name="deviceType" value="">
							<input type="hidden" name="dstatus" value="0">
						</dd>
						<dd>系统：<?php echo $device['os_name'];?></dd>
						<dd>版本：</dd>
						<dd>分辨率：<?php echo $device['resolution_name'];?></dd>
					</dl>
				</a>
			</div>
			
			<?php endforeach?>
			<?php endif?>
		</div>
	</div>
	<div class="content" id="real_test_content" style="display: none;"></div>
<?php $this->load->view('footer');?>